package com.mrogrape.notepad.activity.action.item;

import java.awt.event.ActionEvent;

import javax.swing.Action;

import com.mrogrape.notepad.activity.action.NotepadAction;
import com.mrogrape.notepad.data.ViewContext;
import com.mrogrape.notepad.ui.editor.TextEditor;
import com.mrogrape.util.StringUtils;


public class FromUnicodeMenuItemAction extends NotepadAction {

	/** serialVersionUID */
	private static final long serialVersionUID = -1L;

	public FromUnicodeMenuItemAction(){

		super.putValue(Action.NAME, "From Unincode Tag");
		super.putValue(Action.SHORT_DESCRIPTION, "Convert the unicode tag to text");
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {

		TextEditor editor = ViewContext.getMainFrame().getCurrentTextEditor();

		if(editor != null){

			String text = editor.getSelectedText();
			if(StringUtils.isEmpty(text)){
				return;
			}
			text = StringUtils.escape(text);
			editor.replaceSelection(text);
		}
	}
}
